package internal

import (
	"errors"
	"k9-panel/app/model"
	"k9-panel/app/service/dto"
	"time"
)

type ProjectAdd struct {
	model.Project
	EnvironmentId int `json:"environmentId"`
}
type ProjectListRequest struct {
	Id int `form:"id" `
}
type PrimaryParam struct {
	Id uint `json:"id" form:"id"`
}
type QueryPublishParam struct {
	ProjectName string `json:"projectName" form:"projectName"`
	EnvName     string `json:"envName" form:"envName"`
}

type ConfigDataParam struct {
	ProjectId            int    `form:"projectId"`
	EnvironmentId        uint   `form:"environmentId"`
	DependencyProjectIds []uint `form:"dependencyProjectIds"`
	Content              string `form:"content"`
}

func (c *ConfigDataParam) Valid() error {
	for _, ptr := range c.DependencyProjectIds {
		if ptr == uint(c.ProjectId) {
			return errors.New("项目不能依赖自己！")
		}
	}
	return nil
}

type ConfigReadParam struct {
	ProjectId     int  `form:"projectId"`
	EnvironmentId uint `form:"environmentId"`
}
type PasswordChangeParam struct {
	OldPassword string `form:"oldPassword" `
	Password    string `form:"password"`
	Username    string `form:"username"`
}
type PermSet struct {
	Username string `form:"username" json:"username" binding:"required"`
	EnvCode  string `form:"envCode" json:"envCode" binding:"required"`
	ProCode  string `form:"proCode" json:"proCode" binding:"required"`
}

type AccountListParam struct {
	Username string `form:"username" json:"username" `
}
type AccountDeleteParam struct {
	Username string `form:"username" json:"username" binding:"required"`
}
type AccountAddParam struct {
	Username string `form:"username" json:"username" binding:"required"`
	Password string `form:"password" json:"password" binding:"required"`
}
type AuthParam struct {
	Token string `form:"token" json:"token" binding:"required"`
}
type AuthLoginParam struct {
	Username string `form:"username" json:"username" binding:"required"`
	Password string `form:"password" json:"password" binding:"required"`
}
type AuthRsp struct {
	Token string    `form:"token" json:"token" binding:"required"`
	User  *dto.User `json:"user"`
}
type ConfigPublishParam struct {
	ProjectId     uint   `form:"projectId"`
	EnvironmentId uint   `form:"environmentId"`
	Content       string `form:"content"`
	Memo          string `form:"memo"`
}

type ProjectRsp struct {
	ID          uint      `json:"id"`
	Name        string    `json:"name"`
	Description string    `json:"description"`
	Config      string    `json:"config"`
	Env         []*EnvRsp `json:"environments"`
}
type EnvRsp struct {
	ID          uint   `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
}
type ListHistoryParam struct {
	ProjectId     uint `form:"projectId"`
	EnvironmentId uint `form:"environmentId"`
}
type Page struct {
	Total int64 `json:"total"`
}
type HistoryData struct {
	Id            uint      `json:"id"`
	Content       string    `json:"content"`
	Memo          string    `json:"memo"`
	EnvironmentId int       `json:"environmentId"`
	Status        int8      `json:"status"`
	CreatedAt     time.Time `json:"createdAt"`
}
type HistoryRsp struct {
	Page  Page           `json:"page"`
	Items []*HistoryData `json:"items"`
}

type UserTokenUpdateParam struct {
	Id         uint   `json:"id,omitempty"`
	Desc       string `json:"desc,omitempty"`
	Value      string `json:"value,omitempty"`
	ProjectIds string `json:"projectIds,omitempty"`
	EnvIds     string `json:"envIds,omitempty"`
}
type ListUserTokenParam struct {
	ProjectId     uint `form:"projectId"`
	EnvironmentId uint `form:"environmentId"`
}

type UserTokenRsp struct {
	Id uint `json:"id,omitempty"`

	Desc       string `json:"desc,omitempty"`
	Value      string `json:"value,omitempty"`
	ProjectIds string `json:"projectIds,omitempty"`
	EnvIds     string `json:"envIds,omitempty"`
}
type AccountRsp struct {
	Id        uint      `json:"id,omitempty"`
	Username  string    `json:"username"`
	Super     bool      `json:"super"`
	CreatedAt time.Time `json:"createdAt,omitempty"`
}
